
Imports System.Text
Imports AppsUtility.EncDec
Imports System.Data.SqlClient
Imports System.Configuration

Public Class frmMain

    Inherits System.Windows.Forms.Form

    Dim InvMenu As frmInventoryMain

    Dim masterfrm As frmPayrollHR
    Dim GlMenu As frmGlMain

    Dim SaMenu As frmITAdminMain

    Dim util As New AppsUtility.EncDec
    Public strCon As String = util.toDecrypt(System.Configuration.ConfigurationManager.AppSettings("SQLString"))


    Dim Apos, Awhl, AInv, ALed, Acus, Asup, Ahrm, Afas, Amis, Aadm, Apcp, Abuy, Aatt, Amkt, Aotb As String

    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents ItemContainer9 As DevComponents.DotNetBar.ItemContainer
    Friend WithEvents LabelItem1 As DevComponents.DotNetBar.LabelItem
    Friend WithEvents lblCaption As DevComponents.DotNetBar.Controls.GroupPanel
    Friend WithEvents cmdFinance As DevComponents.DotNetBar.ButtonX
    Friend WithEvents PanelEx1 As DevComponents.DotNetBar.PanelEx
    Friend WithEvents cmdHR As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdInventory As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdService As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmdRetailPOS As DevComponents.DotNetBar.ButtonX
    Friend WithEvents lblDatetime As DevComponents.DotNetBar.LabelX
    Friend WithEvents cmdLogout As DevComponents.DotNetBar.ButtonX
    Friend WithEvents cmbCompany As DevComponents.DotNetBar.Controls.ComboBoxEx
    Friend WithEvents LabelX1 As DevComponents.DotNetBar.LabelX
    Friend WithEvents cmdITadmin As DevComponents.DotNetBar.ButtonX


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.ItemContainer9 = New DevComponents.DotNetBar.ItemContainer()
        Me.LabelItem1 = New DevComponents.DotNetBar.LabelItem()
        Me.lblCaption = New DevComponents.DotNetBar.Controls.GroupPanel()
        Me.PanelEx1 = New DevComponents.DotNetBar.PanelEx()
        Me.cmbCompany = New DevComponents.DotNetBar.Controls.ComboBoxEx()
        Me.LabelX1 = New DevComponents.DotNetBar.LabelX()
        Me.cmdLogout = New DevComponents.DotNetBar.ButtonX()
        Me.lblDatetime = New DevComponents.DotNetBar.LabelX()
        Me.cmdService = New DevComponents.DotNetBar.ButtonX()
        Me.cmdRetailPOS = New DevComponents.DotNetBar.ButtonX()
        Me.cmdInventory = New DevComponents.DotNetBar.ButtonX()
        Me.cmdITadmin = New DevComponents.DotNetBar.ButtonX()
        Me.cmdHR = New DevComponents.DotNetBar.ButtonX()
        Me.cmdFinance = New DevComponents.DotNetBar.ButtonX()
        Me.lblCaption.SuspendLayout()
        Me.PanelEx1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Timer1
        '
        Me.Timer1.Interval = 800
        '
        'ItemContainer9
        '
        '
        '
        '
        Me.ItemContainer9.BackgroundStyle.Class = "RibbonFileMenuColumnTwoContainer"
        Me.ItemContainer9.LayoutOrientation = DevComponents.DotNetBar.eOrientation.Vertical
        Me.ItemContainer9.MinimumSize = New System.Drawing.Size(180, 0)
        Me.ItemContainer9.Name = "ItemContainer9"
        '
        'LabelItem1
        '
        Me.LabelItem1.BorderSide = DevComponents.DotNetBar.eBorderSide.Bottom
        Me.LabelItem1.BorderType = DevComponents.DotNetBar.eBorderType.Etched
        Me.LabelItem1.CanCustomize = False
        Me.LabelItem1.Name = "LabelItem1"
        '
        'lblCaption
        '
        Me.lblCaption.CanvasColor = System.Drawing.SystemColors.Control
        Me.lblCaption.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.lblCaption.Controls.Add(Me.PanelEx1)
        Me.lblCaption.Controls.Add(Me.lblDatetime)
        Me.lblCaption.Controls.Add(Me.cmdService)
        Me.lblCaption.Controls.Add(Me.cmdRetailPOS)
        Me.lblCaption.Controls.Add(Me.cmdInventory)
        Me.lblCaption.Controls.Add(Me.cmdITadmin)
        Me.lblCaption.Controls.Add(Me.cmdHR)
        Me.lblCaption.Controls.Add(Me.cmdFinance)
        Me.lblCaption.Dock = System.Windows.Forms.DockStyle.Fill
        Me.lblCaption.Location = New System.Drawing.Point(0, 0)
        Me.lblCaption.Name = "lblCaption"
        Me.lblCaption.Size = New System.Drawing.Size(731, 441)
        '
        '
        '
        Me.lblCaption.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.lblCaption.Style.BackColorGradientAngle = 90
        Me.lblCaption.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.lblCaption.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.lblCaption.Style.BorderBottomWidth = 1
        Me.lblCaption.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.lblCaption.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.lblCaption.Style.BorderLeftWidth = 1
        Me.lblCaption.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.lblCaption.Style.BorderRightWidth = 1
        Me.lblCaption.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid
        Me.lblCaption.Style.BorderTopWidth = 1
        Me.lblCaption.Style.CornerDiameter = 4
        Me.lblCaption.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded
        Me.lblCaption.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center
        Me.lblCaption.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.lblCaption.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near
        Me.lblCaption.TabIndex = 91
        Me.lblCaption.Text = "Welcome"
        '
        'PanelEx1
        '
        Me.PanelEx1.CanvasColor = System.Drawing.SystemColors.Control
        Me.PanelEx1.ColorScheme.ItemDesignTimeBorder = System.Drawing.Color.Black
        Me.PanelEx1.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007
        Me.PanelEx1.Controls.Add(Me.cmbCompany)
        Me.PanelEx1.Controls.Add(Me.LabelX1)
        Me.PanelEx1.Controls.Add(Me.cmdLogout)
        Me.PanelEx1.Location = New System.Drawing.Point(223, 273)
        Me.PanelEx1.Name = "PanelEx1"
        Me.PanelEx1.Size = New System.Drawing.Size(293, 129)
        Me.PanelEx1.Style.Alignment = System.Drawing.StringAlignment.Center
        Me.PanelEx1.Style.BackColor1.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground
        Me.PanelEx1.Style.BackColor2.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2
        Me.PanelEx1.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine
        Me.PanelEx1.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder
        Me.PanelEx1.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText
        Me.PanelEx1.Style.GradientAngle = 90
        Me.PanelEx1.TabIndex = 92
        '
        'cmbCompany
        '
        Me.cmbCompany.DisplayMember = "Text"
        Me.cmbCompany.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cmbCompany.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbCompany.ItemHeight = 19
        Me.cmbCompany.Location = New System.Drawing.Point(15, 36)
        Me.cmbCompany.Name = "cmbCompany"
        Me.cmbCompany.Size = New System.Drawing.Size(260, 25)
        Me.cmbCompany.TabIndex = 2
        '
        'LabelX1
        '
        Me.LabelX1.BackColor = System.Drawing.Color.Transparent
        Me.LabelX1.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.LabelX1.Location = New System.Drawing.Point(15, 12)
        Me.LabelX1.Name = "LabelX1"
        Me.LabelX1.Size = New System.Drawing.Size(128, 23)
        Me.LabelX1.TabIndex = 93
        Me.LabelX1.Text = "Select Company"
        '
        'cmdLogout
        '
        Me.cmdLogout.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdLogout.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdLogout.Location = New System.Drawing.Point(181, 78)
        Me.cmdLogout.Name = "cmdLogout"
        Me.cmdLogout.Size = New System.Drawing.Size(94, 33)
        Me.cmdLogout.TabIndex = 2
        Me.cmdLogout.Text = "Logou&t"
        '
        'lblDatetime
        '
        Me.lblDatetime.BackColor = System.Drawing.Color.Transparent
        Me.lblDatetime.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.lblDatetime.Location = New System.Drawing.Point(9, 380)
        Me.lblDatetime.Name = "lblDatetime"
        Me.lblDatetime.Size = New System.Drawing.Size(226, 23)
        Me.lblDatetime.TabIndex = 1
        Me.lblDatetime.Text = "Date Time"
        '
        'cmdService
        '
        Me.cmdService.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdService.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdService.Location = New System.Drawing.Point(284, 107)
        Me.cmdService.Name = "cmdService"
        Me.cmdService.Size = New System.Drawing.Size(137, 33)
        Me.cmdService.TabIndex = 0
        Me.cmdService.Tag = "74"
        Me.cmdService.Text = "Service"
        '
        'cmdRetailPOS
        '
        Me.cmdRetailPOS.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdRetailPOS.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdRetailPOS.Location = New System.Drawing.Point(427, 107)
        Me.cmdRetailPOS.Name = "cmdRetailPOS"
        Me.cmdRetailPOS.Size = New System.Drawing.Size(137, 33)
        Me.cmdRetailPOS.TabIndex = 0
        Me.cmdRetailPOS.Tag = "79"
        Me.cmdRetailPOS.Text = "Retail POS"
        '
        'cmdInventory
        '
        Me.cmdInventory.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdInventory.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdInventory.Location = New System.Drawing.Point(284, 41)
        Me.cmdInventory.Name = "cmdInventory"
        Me.cmdInventory.Size = New System.Drawing.Size(137, 33)
        Me.cmdInventory.TabIndex = 0
        Me.cmdInventory.Tag = "2"
        Me.cmdInventory.Text = "Inventory"
        '
        'cmdITadmin
        '
        Me.cmdITadmin.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdITadmin.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdITadmin.Location = New System.Drawing.Point(141, 107)
        Me.cmdITadmin.Name = "cmdITadmin"
        Me.cmdITadmin.Size = New System.Drawing.Size(137, 33)
        Me.cmdITadmin.TabIndex = 0
        Me.cmdITadmin.Tag = "4"
        Me.cmdITadmin.Text = "IT-Administration"
        '
        'cmdHR
        '
        Me.cmdHR.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdHR.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdHR.Location = New System.Drawing.Point(427, 41)
        Me.cmdHR.Name = "cmdHR"
        Me.cmdHR.Size = New System.Drawing.Size(137, 33)
        Me.cmdHR.TabIndex = 0
        Me.cmdHR.Tag = "3"
        Me.cmdHR.Text = "HR/Payroll"
        '
        'cmdFinance
        '
        Me.cmdFinance.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton
        Me.cmdFinance.ForeColor = System.Drawing.Color.FromArgb(CType(CType(0, Byte), Integer), CType(CType(0, Byte), Integer), CType(CType(64, Byte), Integer))
        Me.cmdFinance.Location = New System.Drawing.Point(141, 41)
        Me.cmdFinance.Name = "cmdFinance"
        Me.cmdFinance.Size = New System.Drawing.Size(137, 33)
        Me.cmdFinance.TabIndex = 0
        Me.cmdFinance.Tag = "1"
        Me.cmdFinance.Text = "Finance/Accounts"
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(7, 19)
        Me.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.ClientSize = New System.Drawing.Size(731, 441)
        Me.ControlBox = False
        Me.Controls.Add(Me.lblCaption)
        Me.Font = New System.Drawing.Font("Calibri", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmMain"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Tag = "2"
        Me.lblCaption.ResumeLayout(False)
        Me.PanelEx1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region


    'This will hold user group id from UserProfile table for identifying the user from which group.
    Dim mintUserGroupId As Integer

    Private Sub SerpsLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblDatetime.Text = Now.ToLongDateString & "     " & Now.ToLongTimeString
        Timer1.Enabled = True
        Timer1.Start()

        lblCaption.Text = "Welcome to Inventory Manager - User: " & UserName

        Dim ApData As New APdataLogic
        Dim ds, ds2, ds3, ds4 As DataSet

        ds = ApData.GetUserCompanies(UserID)
        cmbCompany.DataSource = ds.Tables(0)
        cmbCompany.ValueMember = "CompanyID"
        cmbCompany.DisplayMember = "CompanyName"
        CompanyID = cmbCompany.SelectedValue
        If Not IsNumeric(cmbCompany.Text) Then
            CompanyTitle = cmbCompany.Text
        End If

        ds2 = ApData.GetCompanyDepartment(CompanyID)
        DepartmentID = ds2.Tables(0).Rows(0).Item("DepartmentID")

        ds3 = ApData.GetCompanyCenter(CompanyID)
        PostingPC = ds3.Tables(0).Rows(0).Item("AccountCenter")

        ds4 = ApData.GetUserGroup(UserID)
        Dim drow As DataRow
        If ds4.Tables.Count > 0 Then
            For Each drow In ds4.Tables(0).Rows
                UserGroupID = drow("UserGroupID")
                mintUserGroupId = drow("UserGroupID")
                If drow("UserRole") = 2 Then
                    Aadm = "Y"
                Else
                    Aadm = "N"
                End If
            Next
        End If

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub cmdLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogout.Click
        Me.Close()
        Application.Exit()
        Process.Start(Application.StartupPath & "\Retail.exe")
    End Sub


    Private Sub cmbCompany_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCompany.SelectedIndexChanged
        If IsNumeric(cmbCompany.SelectedValue) Then
            CompanyID = cmbCompany.SelectedValue
            CompanyTitle = cmbCompany.Text

            Dim ApData As New APdataLogic
            Dim ds2, ds3 As DataSet

            ds2 = ApData.GetCompanyDepartment(CompanyID)
            DepartmentID = ds2.Tables(0).Rows(0).Item("DepartmentID")

            ds3 = ApData.GetCompanyCenter(CompanyID)
            PostingPC = ds3.Tables(0).Rows(0).Item("AccountCenter")

            ApData = Nothing

        End If
    End Sub

    Private Sub cmdFinance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFinance.Click

        CompanyID = cmbCompany.SelectedValue
        CompanyTitle = cmbCompany.Text

        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, CompanyID, 1) = True Then
            Dim ds2 As DataSet
            ds2 = ApData.GetCompanyDepartment(CompanyID)
            DepartmentID = ds2.Tables(0).Rows(0).Item("DepartmentID")
            GlMenu = New frmGlMain
            GlMenu.ShowDialog()
        Else
            MsgBox("Access Denied !", MsgBoxStyle.Critical, "Inventory Manager")
        End If
        ApData = Nothing
    End Sub

    Private Sub cmdHR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHR.Click

        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, CompanyID, 3) = True Then
            masterfrm = New frmPayrollHR
            masterfrm.ShowDialog()
        Else
            MsgBox("Access Denied !", MsgBoxStyle.Critical, "Inventory Manager")
        End If
        ApData = Nothing
    End Sub

    Private Sub cmdInventory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInventory.Click
        CompanyID = cmbCompany.SelectedValue
        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, CompanyID, 2) = True Then
            Dim ds2 As DataSet
            ds2 = ApData.GetCompanyDepartment(CompanyID)
            DepartmentID = ds2.Tables(0).Rows(0).Item("DepartmentID")
            InvMenu = New frmInventoryMain
            InvMenu.ShowDialog()
        Else
            MsgBox("Access Denied !", MsgBoxStyle.Critical, "Inventory Manager")
        End If
        ApData = Nothing
    End Sub

    Dim usermain As frmITAdminMain
    Dim servmain As frmServiceMain
    Dim POSmain As frmPosMain

    Private Sub cmdITadmin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdITadmin.Click
        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, CompanyID, 4) = True Then
            usermain = New frmITAdminMain
            usermain.ShowDialog()
        Else
            MsgBox("Access Denied !", MsgBoxStyle.Critical, "Inventory Manager")
        End If

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        lblDatetime.Text = Now.ToLongDateString & "     " & Now.ToLongTimeString
        If lblDatetime.ForeColor = Color.DarkGreen Then
            lblDatetime.ForeColor = Color.Purple
        Else
            lblDatetime.ForeColor = Color.DarkGreen
        End If
    End Sub

    Private Sub cmdService_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdService.Click
        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, CompanyID, 74) = True Then
            servmain = New frmServiceMain
            servmain.ShowDialog()
        Else
            MsgBox("Access Denied !", MsgBoxStyle.Critical, "Inventory Manager")
        End If
    End Sub

    Private Sub cmdRetailPOS_Click(sender As System.Object, e As System.EventArgs) Handles cmdRetailPOS.Click
        Dim ApData As New APdataLogic
        If ApData.IsValidUserOption(UserID, CompanyID, 79) = True Then
            POSmain = New frmPosMain
            POSmain.ShowDialog()
        Else
            MsgBox("Access Denied !", MsgBoxStyle.Critical, "Inventory Manager")
        End If
    End Sub

End Class
